const http = require("http");
const fs = require("fs");
const url = require("url");

// module.exports = function(cb, port, success){
//     http.createServer(cb).listen(port, success);
// }
module.exports = {
    server:function(ops){
        http.createServer((req,res)=>{
            const p = url.parse(req.url).pathname;

            fs.readFile("./" + ops.root + p, (err, data)=>{
                if(err){
                    res.write("404")
                }else{
                    res.write(data)
                }
                res.end();
            })

        }).listen(ops.port);
    }
}